#!/bin/bash

#  Run all code to produce gun news datasets and
#  summary statistics / figures of coverage.

mkdir -p results/fig
mkdir -p out-data/

# create out-data/gun_broadcasts.tsv and out-data/program_dates.tsv
jupyter nbconvert --execute tv_news.ipynb

# check that each year/month has news programs in database
echo "Checking news program dates"
stata -b do "program_dates.do"

# convert gun-related broadcasts to a Stata dataset with shooting info
echo "Building out-data/gun_news.dta"
stata -b do "gun_news.do"

# produce figures of gun-related news coverage over time
for i in fig_*.do;
do
    echo "Running $i"
    stata -b do "$i"
done;

# measure news for each mass shooting
echo "Building out-data/news_by_shooting.dta"
stata -b do "news_by_shooting.do"

echo "Running reg_shoot_coverage.do regressions"
stata -b do "reg_shoot_coverage.do"

echo "Done"
